/**************************************************
Core_Input.h
GameCore Component

Programming Role-Playing Games with DirectX, 2nd Edition
by Jim Adams (Jan 2004)
**************************************************/

#ifndef _CORE_INPUT_H_
#define _CORE_INPUT_H_

// Enumerated list of of device types
enum InputDevices
{
	NONE = 0,
	KEYBOARD,
	MOUSE,
	JOYSTICK
};

///////////////////////////////////////////////////////////////////////
// Class definitions
///////////////////////////////////////////////////////////////////////
class cInput;
class cInputDevice;

class cInput  
{
  protected:
      HWND           m_hWnd;
      IDirectInput8 *m_pDI;

  public:
    cInput();
    ~cInput();

    IDirectInput8 *GetDirectInputCOM();
    HWND           GethWnd();
    
    BOOL Init(HWND hWnd, HINSTANCE hInst);
    BOOL Shutdown();
};

class cInputDevice
{
  public:
    cInput               *m_Input;

    short                 m_Type;
    IDirectInputDevice8  *m_pDIDevice;

    BOOL                  m_Windowed;

    char                  m_State[256];
    DIMOUSESTATE         *m_MouseState;
    DIJOYSTATE           *m_JoystickState;

    BOOL                  m_Locks[256];

    long                  m_XPos, m_YPos;
      
    static BOOL FAR PASCAL EnumJoysticks(LPCDIDEVICEINSTANCE pdInst, LPVOID pvRef);

  public:
    cInputDevice();
    ~cInputDevice();

    IDirectInputDevice8 *DeviceCOM();

    // Generic functions - all devices
    BOOL Create(cInput *Input, short Type, BOOL Windowed = TRUE);
    BOOL Free();

    BOOL Clear();
    BOOL Read();
    BOOL Acquire(BOOL Active = TRUE);

    BOOL GetLock(char Num);
    BOOL SetLock(char Num, BOOL State = TRUE);

    long GetXPos();
    BOOL SetXPos(long XPos);
    long GetYPos();
    BOOL SetYPos(long YPos);
    long GetXDelta();
    long GetYDelta();

    // Keyboard specific functions
    BOOL  GetKeyState(unsigned char Num);
    BOOL  SetKeyState(char Num, BOOL State);
    BOOL  GetPureKeyState(char Num);
    short GetKeypress(long TimeOut = 0);
    long  GetNumKeyPresses();
    long  GetNumPureKeyPresses();

    // Mouse/Joystick specific functions
    BOOL  GetButtonState(char Num);
    BOOL  SetButtonState(char Num, BOOL State);
    BOOL  GetPureButtonState(char Num);
    long  GetNumButtonPresses();
    long  GetNumPureButtonPresses();
};

#endif
